<?php
/**
 * Stats de base
 * Utilise artichow 1.1.0 PHP5
 * **/

require 'kernel/common.php';

$template->set_filenames(array('stats' => 'template/stats.tpl'));
#Annonce totale active
$TotA = $db->sql_query("SELECT count(id) as totale FROM immo_annonce WHERE active = 1",'ARRAY');
#Annonce total db
$TotAfull = $db->sql_query("SELECT count(id) as totale FROM immo_annonce",'ARRAY');

// REPARTITION ANNONCE TYPE
foreach($type_array as $key => $value)
{
    $t_tmp = $db->sql_query("SELECT count(id) as tot FROM immo_annonce WHERE active = 1 AND type = '". $key ."'",'ARRAY');
    if($t_tmp['tot'] != 0)$type_compteur[$key] = $t_tmp['tot'];
    $template->assign_block_vars('rat', array(
    'V_TYPE' =>  parse_simple($value),
    'V_POURCENT' =>  round(($type_compteur[''. $key . '']*100) / $TotA['totale'],2),
    'V_VALEUR'    =>  $t_tmp['tot'],
    ));
} 

// ANNONCE VENDU
$AV = $db->sql_query("SELECT count(id) as annonce_non_vendu,
    (SELECT COUNT(id) FROM immo_annonce WHERE vendu = 1) as annonce_vendu_agence,
    (SELECT COUNT(id) FROM immo_annonce WHERE vendu = 2) as annonce_vendu_c
    FROM immo_annonce
    WHERE vendu = 0",'ARRAY');
$av_array = array ($AV['annonce_non_vendu'], $AV['annonce_vendu_agence'], $AV['annonce_vendu_c']);
$av_legend = array('Non vendu','Vendu Agence','Vendu Concurence');

// ANNONCE PAR AGENCE



$template->assign_vars(array(
'L_TOTAL_ANNONCE'   =>  $lang['Annonce_totale'],
'L_REPARTION_ANNONCES_TYPE' =>  $lang['Repartition_annonce_type'],
'L_STATISTIQUE' =>  $lang['Statistiques'],
'L_TYPE'    =>  $lang['Type'],
'L_POURCENTAGE' =>  $lang['Pourcentage'],
'L_VALEUR'  =>  $lang['Valeur'],
'L_VENTE_ANNONCE'   =>  $lang['Vente_annonce'],
'L_ANNONCE_NON_VENDU'   =>  $lang['Annonce_non_vendu'],
'L_ANNONCE_VENDU_AGENCE'    =>  $lang['Annonce_vendu_agence'],
'L_ANNONCE_VENDU_C'    =>  $lang['Annonce_vendu_concurence'],
'V_RAT_VALUES'  =>  urlencode(serialize($type_compteur)),
'V_RAT_LEGEND'  =>  urlencode(serialize($type_array)),
'V_AV_VALUES'   =>  urlencode(serialize($av_array)),
'V_AV_LEGEND'   =>  urlencode(serialize($av_legend)),
'V_TOT_FULL_ANNONCE' => $TotAfull['totale'],
'V_TOTAL_ANNONCE_ACTIVE'    =>  $TotA['totale'],
'V_ANNONCE_NON_VENDU'   =>  $AV['annonce_non_vendu'],
'V_ANNONCE_NON_VENDU_POURCENT'   =>  round(($AV['annonce_non_vendu'] * 100 ) / $TotAfull['totale'],2),
'V_ANNONCE_VENDU_AGENCE'    =>  $AV['annonce_vendu_agence'],
'V_ANNONCE_VENDU_AGENCE_POURCENT'   =>  round(($AV['annonce_vendu_agence'] * 100 ) / $TotAfull['totale'],2),
'V_ANNONCE_VENDU_C'    =>  $AV['annonce_vendu_c'],
'V_ANNONCE_VENDU_C_POURCENT'   =>  round(($AV['annonce_vendu_c'] * 100 ) / $TotAfull['totale'],2),
));
$template->display('stats');
require 'footer.php';
 ?>